
package org.upt.dcda.presentation;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.naming.InitialContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.upt.dcda.BookManager;
import org.upt.dcda.BookManagerBeanRemote;
import org.upt.dcda.db.TagEntity;

public class BookInformation
{

	@EJB
	private BookManagerBeanRemote	bookManagerBean;

	public List<Integer> getAllBooktagsIdByBookId(HttpServletRequest request, HttpServletResponse response)
	{
		List<Integer> tagsId = new ArrayList<Integer>();
		try
		{
			int bookId = Integer.valueOf(request.getParameter("id"));
			InitialContext initContext = new InitialContext();
			this.bookManagerBean = (BookManagerBeanRemote) initContext.lookup(BookManager.BOOK_BEAN_NAME);

			for (TagEntity te : this.bookManagerBean.getBooktagsByBookId(bookId))
			{
				tagsId.add(te.getTagId());
			}

		}
		catch (Throwable be)
		{
			try
			{
				request.getServletContext().log("Caught Exception: " + be, be);
				response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, be.toString());
			}
			catch (IOException e)
			{
				request.getServletContext().log("Caught IOException: " + e, e);
			}
		}
		return tagsId;
	}
}
